<template>
  <div class="dd-container">
    <img class="ca-text" src="../../assets/images/CompositeAnalysis/ca-text.png" alt="">
    <div class="ddc-header">
      <div class="search">
        <div class="search-content">
          <input class="search-input" v-model="search" placeholder="请输入企业名称或统一社会信用代码" />
          <div class="btn" @click="searchHander">
            <img src="../../assets/images/DueDiligence/search.png" alt="">
          </div>
        </div>
      </div>
      <div class="report-list">
        <div class="list-header">
          <h3>报告列表</h3>
        </div>
        <el-table :header-cell-style="{ background: '#f5f6fa', height: '55px', color: '#000000' }" stripe
          class="list-body" :data="tableData">
          <el-table-column align="center" prop="id" label="序号" width="80" />
          <el-table-column align="center" prop="company" label="企业名称" width="250" />
          <el-table-column align="center" prop="reportType" label="报告类型" />
          <el-table-column align="center" prop="reportStatus" label="报告状态">
            <template #default="scope">
              <span style="color: #0B70CF;" v-if="scope.row.reportStatus == '已生成'">{{ scope.row.reportStatus }}</span>
              <span style="color: #FF7404;" v-if="scope.row.reportStatus == '生成中'">{{ scope.row.reportStatus }}</span>
              <span style="color: #FF0404;" v-if="scope.row.reportStatus == '未获取'">{{ scope.row.reportStatus }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="toggleReport" label="是否纳入综合分析报告">
            <template #default="scope">
              <el-switch v-model="scope.row.toggleReport" :disabled="scope.row.reportStatus == '未获取'" />
            </template>
          </el-table-column>
          <el-table-column class="handle" align="center" label="操作">
            <template #default="scope">
              <span>查看</span>
              <span style="margin-left: 40px;">导出</span>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination class="pagination" background layout="prev, pager, next" :total="1000" />
        <div class="list-footer">
          <div class="btn" @click="onReport">
            <img src="../../assets/images/CompositeAnalysis/button-icon.png" alt="">
            <span>行业分析预览</span>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- 行业分析报告对话框 -->
  <el-dialog center v-model="dialogReportVisible" title="行业分析预览" width="800" top="10vh">
    <el-scrollbar height="500">
      <vue-pdf-embed :source="pdfState.url" v-for="page in pdfState.numPages" :page="page" :key="page" textLayer
        ref="vuePdfRef" />
    </el-scrollbar>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogReportVisible = false">关闭预览</el-button>
        <el-button type="primary" @click="onPDFDownload">导出报告</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, reactive, onMounted, computed } from "vue"
// 引入PDF
import VuePdfEmbed from "vue-pdf-embed";
import { createLoadingTask } from "vue3-pdfjs/esm";

const search = ref('')
const dialogReportVisible = ref(false)
const vuePdfRef = ref(null);

// 文件路径
import pdfUrl from '../../assets/pdf/uniapp.pdf';

const pdfState = reactive({
  url: pdfUrl,
  // 当前页
  pageNum: 1,
  // 总页数
  numPages: 1,
})

onMounted(() => {
  const loadingTask = createLoadingTask(pdfState.url);
  loadingTask.promise.then((pdf) => {
    // 获取页面总页数
    pdfState.numPages = pdf.numPages;
  });
});

function getPDFFileName() {
  const last_index = pdfState.url.lastIndexOf('/');
  return pdfState.url.slice(last_index + 1);
}

const onPDFDownload = () => {
  vuePdfRef.value[0].download(getPDFFileName());
}

const searchHander = () => {
  console.log(search.value);
}

const onReport = () => {
  dialogReportVisible.value = true
}

const tableData = [
  {
    id: 1,
    company: "北京中研硕福科技有限公司",
    reportType: "企业准入分析报告",
    reportStatus: "已生成",
    toggleReport: true
  },
  {
    id: 2,
    company: "北京中研硕福科技有限公司",
    reportType: "企业准入分析报告",
    reportStatus: "生成中",
    toggleReport: true
  },
  {
    id: 3,
    company: "北京中研硕福科技有限公司",
    reportType: "企业准入分析报告",
    reportStatus: "未获取",
    toggleReport: false
  },
  {
    id: 4,
    company: "北京中研硕福科技有限公司",
    reportType: "企业准入分析报告",
    reportStatus: "未获取",
    toggleReport: false
  },
  {
    id: 5,
    company: "北京中研硕福科技有限公司",
    reportType: "企业准入分析报告",
    reportStatus: "未获取",
    toggleReport: false
  }
]
</script>

<style lang="less" scoped>
.dd-container {
  background: #fff;
  height: calc(100vh - 70px);
  background: url("../../assets/images/CompositeAnalysis/ca-bg.png") no-repeat;
  background-size: cover;
  text-align: center;

  .ca-text {
    width: 350px;
    padding-top: 50px;
  }

  .ddc-header {
    width: 100%;
    position: relative;

    .dd-bg {
      width: 100%;
    }

    .search {
      width: 80%;
      height: 130px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 0 auto;

      .search-content {
        width: 80%;
        display: flex;

        .search-input {
          flex: 1;
          height: 70px;
          outline: none !important;
          padding-left: 20px;
          box-sizing: border-box;
          font-size: 18px;
          border-top-left-radius: 10px;
          border-bottom-left-radius: 10px;
          border: 2px solid #536EF7;
        }

        .btn {
          width: 150px;
          height: 70px;
          background-color: #536EF7;
          display: flex;
          align-items: center;
          justify-content: center;
          border-top-right-radius: 10px;
          border-bottom-right-radius: 10px;

          img {
            width: 25px;
            height: 25px;
            margin-right: 10px;
          }

          span {
            font-weight: bold;
            font-size: 20px;
            color: #FFFFFF;
          }
        }
      }
    }

    .report-list {
      .list-header {
        background-color: #fff;
        width: 80%;
        height: 80px;
        line-height: 80px;
        margin: 0 auto;
        margin-bottom: 2px;
        box-shadow: 0 5px 20px rgba(100, 100, 100, .2);
        border-top-left-radius: 10px;
        border-top-right-radius: 10px;

        h3 {
          font-size: 18px;
          color: #202020;
          padding-left: 40px;
        }
      }

      .list-body {
        width: 80%;
        margin: 0 auto;
        box-shadow: 0 5px 20px rgba(100, 100, 100, .2);
        margin-bottom: 1px;
      }

      .pagination {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #fff;
        width: 80%;
        height: 80px;
        line-height: 80px;
        margin: 0 auto;
        box-shadow: 0 5px 20px rgba(100, 100, 100, .2);
        z-index: 99;
        border-bottom-left-radius: 10px;
        border-bottom-right-radius: 10px;
      }

      .list-footer {
        padding: 20px 0;
        display: flex;
        justify-content: center;

        .btn {
          display: flex;
          width: 150px;
          height: 40px;
          background-color: #536EF7;
          color: #fff;
          line-height: 40px;
          text-align: center;
          cursor: pointer;
          justify-content: center;
          align-items: center;
          border-radius: 5px;
          img{
            display: block;
            width: 20px;
          }
          span{
            margin-left: 10px;
          }
        }
      }
    }
  }
}
</style>
